import { getAllRoleList, isAccountExist } from '@/api/sys/system'
import { BasicColumn, FormSchema } from '@/components/Table'

export const columns: BasicColumn[] = [
  {
    title: '设备编码',
    dataIndex: 'devicCode',
  },
  {
    title: '设备名称',
    dataIndex: 'deviceName',
  },
  {
    title: '属性',
    dataIndex: 'propertyName',
  },
  {
    title: '单位',
    dataIndex: 'unitName',
  },
  {
    title: '采集值',
    dataIndex: 'measureValue',
  },
  {
    title: '采集时间',
    dataIndex: 'measureTime',
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'code',
    label: '设备编码',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'time',
    component: 'RangePicker',
    colProps: { span: 12 },
    // label: '起止日期',
  },
]

export const accountFormSchema: FormSchema[] = [
  {
    label: '数据分类',
    field: 'type',
    component: 'ApiSelect',
    componentProps: {
      api: getAllRoleList,
      labelField: 'roleName',
      valueField: 'roleValue',
    },
    required: true,
  },
  {
    field: 'name',
    label: '数据名称',
    component: 'Input',
    helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
    rules: [
      {
        required: true,
        message: '请输入用户名',
      },
      {
        trigger: 'blur',
        validator(_, value) {
          return new Promise((resolve, reject) => {
            if (!value) return resolve()
            isAccountExist(value)
              .then(resolve)
              .catch((err) => {
                reject(err.message || '验证失败')
              })
          })
        },
      },
    ],
  },
  {
    field: 'code',
    label: '设备参数',
    component: 'Input',
    required: true,
    ifShow: false,
  },
  {
    field: 'createtime',
    label: '数据日期',
    component: 'DatePicker',
  },
  {
    field: 'value',
    label: '参数值',
    component: 'InputNumber',
  },
]
